#include "talkwindow.h"
#include "ui_talkwindow.h"

#include <QJsonDocument>
#include <QMessageBox>

TalkWindow::TalkWindow(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::TalkWindow)
{
    ui->setupUi(this);
    this->setWindowTitle("聊天页面");

    setWindowFlags(Qt::WindowCloseButtonHint);
    connect(this,&TalkWindow::signal_GetPerInfo,this,&TalkWindow::getChessFromPeer);
}

TalkWindow::~TalkWindow()
{
    delete ui;
}

void TalkWindow::setConnectStatus(QString status)
{
    ui->label->setText(status);
}

void TalkWindow::on_pushButton_clicked()
{
    if(ui->label->text()=="未连接")
    {
        QMessageBox::about(nullptr,"未连接","err");
        return;
    }

    QString info=ui->textEdit_send_talking_info->toPlainText();


    emit sendInfo(info);
    ui->textEdit_send_talking_info->clear();

    ui->textEdit->append(QString("你:")+info);
    update();
}

void TalkWindow::getChessFromPeer(QString info)
{
    emit signal_GetPerInfo(info);
}

void TalkWindow::getPerInfo(QString info)
{
    ui->textEdit->append(QString("对方:")+info.toStdString().c_str());
    update();
}
